<?php

class Control_Gm_getSendLogsAjax
{
    function getSendLogsAjax()
    {
        $startTime = strtotime( MooForm::post('sendStartTime'));
        $endTime = strtotime(MooForm::post('sendEndTime'))+84599;
        $gm_awardsinfo = MooConfig::get('gm_awardstype.type');
        $gm_awardsLists = MooConfig::get('gm_awardsinfo.giftIds');

        $awardLogDao =  MooDao::get('AwardLog');
        $sendlogs = $awardLogDao->getAll("SELECT * FROM @TABLE WHERE send_time>".$startTime." and send_time < ".$endTime);
        if($sendlogs){
            foreach ($sendlogs as $key => $value){
                $sendlogs[$key]['send_time'] = date('Y-m-d H:i:s',$value['send_time']);
                if($value['playerid'] == '-1'){
                    $sendlogs[$key]['playerid'] = '全服玩家';
                }
                $curSendContentStr = '';
                if($value['award_info']){
                    $curSendContentsArr = explode(',',$value['award_info']);
                    foreach ($curSendContentsArr as $curSendContent){
                        $curSendContentArr = explode('_',$curSendContent);
                        foreach ($gm_awardsinfo as $awardstype){
                            if($curSendContentArr[0] == $awardstype['id']){
                                $curContentType = $awardstype['name'];
                                break;
                            }
                        }
                        foreach ($gm_awardsLists as $gm_awardsList){
                            if($gm_awardsList['type'] == $curSendContentArr[0] && $gm_awardsList['itemId'] == $curSendContentArr[1]){
                                $curContentName = $gm_awardsList['name'];
                            }
                        }
                        $curSendContentStr.="[".$curContentType."]";
                        $curSendContentStr.=$curContentName;
                        $curSendContentStr.="(数量:".$curSendContentArr[2].")<br/>";
                    }
                }else{
                    $curSendContentStr = '没有邮件附件';
                }
                $sendlogs[$key]['sendContentStr']  = $curSendContentStr;
            }
            $data = $sendlogs;
        }else{
            $data = array();
        }



        $resData = array('code'=>0,'msg'=>'success','data'=>$data);
        $rs = MooJson::encode($resData);
        exit($rs);

    }

}